/*
 * Copyright (c) 2020 Tunaiyi
 * Tny Framework is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

package com.tny.game.common.lifecycle.unit;

import com.tny.game.common.lifecycle.unit.annotation.*;

/**
 * <p>
 *
 * @author : kgtny
 * @date : 2021/8/18 2:33 下午
 */
public final class UnitNames {

    public static final String DEFAULT_HEAD = "default";

    private UnitNames() {
    }

    public static String defaultName(Class<?> clazz) {
        return DEFAULT_HEAD + clazz.getSimpleName();
    }

    public static String lowerCamelName(Class<?> clazz) {
        String name = clazz.getSimpleName();
        return name.substring(0, 1).toLowerCase() + name.substring(1);
    }

    public static String lowerCamelName(String name) {
        return name.substring(0, 1).toLowerCase() + name.substring(1);
    }

    public static String unitName(String key, Class<?> clazz) {
        return key + clazz.getSimpleName();
    }

    public static String getUnitName(Object value) {
        Class<?> clazz = value.getClass();
        Unit unit = clazz.getAnnotation(Unit.class);
        if (unit != null) {
            return unit.value();
        }
        return clazz.getSimpleName();
    }

}
